﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using TelecoSystems.Modules.Products.Views;
using TelecoSystems.Infrastructure;
using TelecoSystems.Web.Services.Products;
using TelecoSystems.Web.Services.Variants;
using System.Collections.Generic;

namespace TelecoSystems.Modules.Products
{
    public class ProductsModule : IModule
    {
        private readonly IRegionManager regionManager;
        private readonly IUnityContainer unityContainer;
        private const string MODULE_NAME = "Products";

        public ProductsModule(IRegionManager _regionManager, IUnityContainer _unityContainer)
        {
            regionManager = _regionManager;
            unityContainer = _unityContainer;
        }

        public void Initialize()
        {
            //Register Domain Contexts which are being used in the module
            unityContainer.RegisterType<ProductsDomainContext>(new InjectionConstructor());
            unityContainer.RegisterType<VariantsDomainContext>(new InjectionConstructor());
                                    
            //Locate the base module view
            ProductsModuleView pmView = this.unityContainer.Resolve<ProductsModuleView>();
            //Locate the Main Shell region and add module view to it
            IRegion region = regionManager.Regions[RegionNames.MainRegion];            
            region.Add(pmView, pmView.GetType().Name);
            region.Activate(pmView);

            //Register main module views with the Products's module region
            region = regionManager.Regions[MODULE_NAME + RegionNames.ModuleRegion];
            regionManager.RegisterViewWithRegion(MODULE_NAME + RegionNames.ModuleRegion,
                () => this.unityContainer.Resolve<ProductsBrowseView>());
            regionManager.RegisterViewWithRegion(MODULE_NAME + RegionNames.ModuleRegion,
                () => this.unityContainer.Resolve<ProductsReportsView>());
        }

    }
}
